const path = require('path');
const ExtractCss = require('extract-text-webpack-plugin');
const HtmlPlugin = require('html-webpack-plugin');
module.exports = {
    // entry:'./src/js/index.js',
    entry:{
        index:'./src/js/index.js',
        detail:'./src/js/detail.js'
    },
    // entry:['./src/js/index.js','./src/js/getDate.js'],
    output:{
        path:path.join(__dirname,'/dist'),
        filename:'./js/[name].js'
    },
    mode:'development',
    module:{
        rules:[
            {
                test:/\.js$/,
                exclude:/node_modules/,
                // use:{
                //     loader:'babel-loader',
                //     options:{
                //         presets:['@babel/preset-env']
                //     }
                // }
                loader:'babel-loader'
            },
            {
                test:/\.scss$/,
                use:ExtractCss.extract({
                    fallback:'style-loader',
                    use:['css-loader','sass-loader']
                })
                // loader:['style-loader','css-loader','sass-loader']
            },
            {
                test:/\.css$/,
                use:['css-loader']
            },
            {
                test:/\.(png|jpg|gif|eot|svg|ttf|woff|woff2)$/,
                use:{
                    loader:'url-loader',
                    options:{
                        fallback:'file-loader',
                        name:'img/[name].[ext]',
                        publicPath:'/',
                        limit:10,  //1b = 1kb  1000kb = 1MB 1000MB = 1GB
                    }
                }
            },
            {
                test:/\.html$/,
                use:{
                    loader:'html-loader',
                    options:{
                        attrs:['img:src']
                    }
                }
            }
        ]
    },
    plugins:[
        new ExtractCss({
            filename:'./css/index.css'
        }),
        new HtmlPlugin({
            template:'./src/index.html',
            inject:true,
            title:'首页',
            chunks:['index'],
            // // title:'首页',
            filename:'index.html'
        }),
        new HtmlPlugin({
            template:'./src/detail.html',
            inject:true,
            title:'详情',
            chunks:['detail'],
            // // title:'首页',
            filename:'detail.html'
        }),
    ],
    devServer:{
        port:9090,
        contentBase:'./dist'
    }
}
